package com.zhentao.controller;

import com.zhentao.service.ReportService;
import com.zhentao.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/analysis/report")
public class ReportController {

    @Autowired
    private ReportService reportService;

    // 1. 商品库存统计
    @GetMapping("/product-stock")
    public List<ProductStockReportVO> getProductStockReport() {
        try {
            return reportService.getProductStockReport();
        } catch (Exception e) {
            return new ArrayList<>();
        }
    }

    // 2. 账户统计
    @GetMapping("/account")
    public List<AccountReportVO> getAccountReport() {
        try {
            return reportService.getAccountReport();
        } catch (Exception e) {
            return new ArrayList<>();
        }
    }

    // 3. 零售统计
    @GetMapping("/retail")
    public List<RetailReportVO> getRetailReport() {
        try {
            return reportService.getRetailReport();
        } catch (Exception e) {
            return new ArrayList<>();
        }
    }

    // 4. 采购统计
    @GetMapping("/purchase")
    public List<PurchaseReportVO> getPurchaseReport() {
        try {
            return reportService.getPurchaseReport();
        } catch (Exception e) {
            return new ArrayList<>();
        }
    }

    // 5. 销售统计
    @GetMapping("/sale")
    public List<SaleReportVO> getSaleReport() {
        try {
            return reportService.getSaleReport();
        } catch (Exception e) {
            return new ArrayList<>();
        }
    }

    // 6. 进销存统计
    @GetMapping("/inventory-flow")
    public List<InventoryFlowReportVO> getInventoryFlowReport() {
        try {
            return reportService.getInventoryFlowReport();
        } catch (Exception e) {
            return new ArrayList<>();
        }
    }

    // 7. 库存预警
    @GetMapping("/stock-warning")
    public List<StockWarningVO> getStockWarning() {
        try {
            return reportService.getStockWarning();
        } catch (Exception e) {
            return new ArrayList<>();
        }
    }

    // ======== 以下为补充的报表接口（如服务层暂无实现，先返回示例聚合数据） ========

    // 8. 销售利润统计（示例：金额、成本、利润）
    @GetMapping("/sales-profit")
    public List<Map<String, Object>> getSalesProfit() {
        try {
            return reportService.getSalesProfitReport();
        } catch (Exception e) {
            return new ArrayList<>();
        }
    }

    // 9. 销售排行（示例：TOP 商品）
    @GetMapping("/sales-rank")
    public List<Map<String, Object>> getSalesRank() {
        try {
            return reportService.getSalesRankReport();
        } catch (Exception e) {
            return new ArrayList<>();
        }
    }

    // 10. 销售占比（示例：品类占比）
    @GetMapping("/sales-ratio")
    public List<Map<String, Object>> getSalesRatio() {
        try {
            return reportService.getSalesRatioReport();
        } catch (Exception e) {
            return new ArrayList<>();
        }
    }

    // 11. 负库存列表（示例：负库存商品）
    @GetMapping("/negative-stock")
    public List<Map<String, Object>> getNegativeStock() {
        try {
            return reportService.getNegativeStockReport();
        } catch (Exception e) {
            return new ArrayList<>();
        }
    }

    // 12. 多属性库存（示例：颜色/尺码维度）
    @GetMapping("/multi-attr-stock")
    public List<Map<String, Object>> getMultiAttrStock() {
        try {
            return reportService.getMultiAttrStockReport();
        } catch (Exception e) {
            return new ArrayList<>();
        }
    }

    // 13. 绩效统计（示例：业务员/完成额）
    @GetMapping("/performance")
    public List<Map<String, Object>> getPerformance() {
        try {
            return reportService.getPerformanceReport();
        } catch (Exception e) {
            return new ArrayList<>();
        }
    }
}
